/**
 * Copyright (C) 2008 aileron.cc
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package cc.aileron.commons.accessor.properties;

import java.util.Map;

import cc.aileron.commons.exception.NoSuchAccessorRuntimeException;

/**
 * Pojo-accessor-map
 * @author Aileron
 *
 */
public class PojoPropertiesMap <T extends Map<String,Object>> implements PojoProperties<T>
{
    /**
     * 自分自身のインスタンスを指定する場合のキーワード
     */
    private static final String SELF = "self";
    
    /*
     * (非 Javadoc)
     * @see cc.aileron.commons.accessor.PojoProperties#getObject(java.lang.String)
     */
    public Object getObject(String name) throws NoSuchAccessorRuntimeException
    {
        if(SELF.equals(name))
        {
            return map;
        }
        return map.get(name);
    }

    /*
     * (非 Javadoc)
     * @see cc.aileron.commons.accessor.PojoProperties#setObject(java.lang.String, java.lang.Object)
     */
    public void setObject(String name, Object value)
            throws NoSuchAccessorRuntimeException
    {
        map.put(name, value);
    }
    
    /*
     * (非 Javadoc)
     * @see cc.aileron.commons.accessor.PojoProperties#toTarget()
     */
    @SuppressWarnings("unchecked")
    public T toTarget()
    {
        return (T) map;
    }
    
    /*
     * (非 Javadoc)
     * @see cc.aileron.commons.accessor.PojoProperties#newPropertieInstance(java.lang.String)
     */
    public Object newPropertieInstance(final String name)
    {
        return null;
    }
    
    /**
     * constractor set map
     * @param map
     */
    public PojoPropertiesMap(final Map<String,Object> map)
    {
        this.map = map;
    }  
    
    /**
     * map
     */
    private final Map<String,Object> map ;
}